package com.lagou.dao.impl;

import com.lagou.dao.ArticleDao;
import com.lagou.domain.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ArticleDaoImpl implements ArticleDao {



    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<Article> findAll() {
        // 编写sql
        String sql = "SELECT * FROM t_comment";

        List<Article> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Article>(Article.class));
        return list;
    }

    @Override
    public void save(Article article) {
        String sql = "INSERT INTO t_article VALUES(?,?,?)";
        jdbcTemplate.update(sql, article.getId(), article.getTitle(), article.getContent());

    }

}
